#!/usr/bin/env bash
set -e

# SoX Resampler Library       Copyright (c) 2007-16 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1                  See LICENCE for details.

# Tests interpolating then decimating by the same, large ratio.

tool=../examples/3-options-input-fn
w=$(echo -e "`sox --ver |sed 's/.*SoX v//'` d\n14.4.1 k"|sort -Vr|head -1|sed 's/.* //')
q=4
test x$1 = x && ratio=1e5 || ratio=$1
test x$2 = x && rate=8000 || rate=$2

sox -r$rate -n 1.s32 synth 10 sin 0:`expr $rate / 2` vol .9375
sync

time { $tool 1 $ratio 1 2 1 $q a < 1.s32 | $tool $ratio 1 1 1 2 $q a > 2.s32;}

sox -mv-1 -r$rate -c1 1.s32 -r$rate -c1 2.s32 -n spectrogram -hw$w -z150 -o lr-$w.png -c "large-ratio-test q:$q ratio:$ratio"

rm [12].s32
